assignment8

Author

ChenL

question 1.3

#Call the ACS API, returns a sf object
mn_median_value.df <- get_acs(
  geography = "cbg",
  variables = "B25077_001", 
  state     = "MN",
  county = "Hennepin",
  year      = 2020,
  geometry  = TRUE
) 
#Add text label
mn_label.df <- mn_median_value.df %>%
  mutate(
    cbg = str_split(NAME,",")%>%
      map_chr(1)%>%str_remove("Census Tract "),
    text_label = str_c("cbg",cbg, 
                       "\nMedianValue - " ,
                       scales::dollar(estimate)
                      )
  )

value <- ggplot() + 
  geom_sf(data = mn_label.df, 
          aes(fill = estimate, text = text_label),
          colour = "black", size = 0.02)  + 
  scale_fill_viridis_c("Median Value", labels = scales::dollar) + 
  theme_void() +
  theme(legend.position = "right")+
  labs(title="Median House Value in Hennepin County in 2020")

ggplotly(value, tooltip = "text") %>%
    style(hoveron = "fills")